unit ThreadUnit;

interface
uses
  System.Classes, System.SysUtils;
type

  TAnonymousThreadX<T> = class(TThread)
  private
    FProc: TProc<T>;
    AValue:T;
  protected
    procedure Execute; override;
  public
    constructor Create(const AProc: TProc<T>;ProcPar:T);
  end;

  TThreadHelper= class helper for TThread
    public
      class function CreateAnonymousThreadX<T>(const ThreadProc: TProc<T>;proPar:T): TThread; static;
  end;

implementation

{ TAnonymousThreadX }

constructor TAnonymousThreadX<T>.Create(const AProc: TProc<T>;ProcPar:T);
begin
  inherited Create(True);
  FreeOnTerminate := True;
  FProc := AProc;
  Avalue:=ProcPar;
end;

procedure TAnonymousThreadX<T>.Execute;
begin
  inherited;
  FProc(Avalue);
end;

{ TThreadHelper }

class function TThreadHelper.CreateAnonymousThreadX<T>(const ThreadProc: TProc<T>; proPar: T): TThread;
begin
  Result := TAnonymousThreadX<T>.Create(ThreadProc,proPar);
end;

end.
